﻿using com.kmer.ApiServer;
using OrderAPI;
using System;
using System.Web;
using TouchUIWeiXinAPI;
using WxNewOrderAPI;

namespace km_web_api
{
    public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            TokenHandler.InitWebAccessToken();

            APIHandlerFactory.Register(typeof(TokenHandler));
            APIHandlerFactory.Register(typeof(CoreHandler));
            APIHandlerFactory.Register(typeof(TestHandler));

            //注册业务API服务
            APIHandlerFactory.FindAndRegister(typeof(TrialChooseVersionIPadHandler).Assembly);
            APIHandlerFactory.Register(typeof(BaseAPI.UsersHandler));
            APIHandlerFactory.Register(typeof(BaseAPI.ImageHandler));
            APIHandlerFactory.Register(typeof(BaseAPI.LoginHandler));
            APIHandlerFactory.Register(typeof(TrialChooseVersionIPadHandler));
            APIHandlerFactory.WXRegister(typeof(WXCodeHandler));
            APIHandlerFactory.WXRegister(typeof(WXLoginHandler));
            APIHandlerFactory.WXRegister(typeof(WXOrderHandler));
            APIHandlerFactory.WXRegister(typeof(WXImageHandler));
            APIHandlerFactory.WXRegister(typeof(WXOrderResultHandler));
            APIHandlerFactory.WXRegister(typeof(WXNewCodeHandler));
            APIHandlerFactory.WXRegister(typeof(WXNewLoginHandler));
            APIHandlerFactory.WXRegister(typeof(WXNewOrderHandler));
            APIHandlerFactory.WXRegister(typeof(WXNewImageHandler));
            APIHandlerFactory.WXRegister(typeof(WXNewOrderResultHandler));
        }


        private void Session_Start(object sender, EventArgs e)
        {
            //try
            //{
            //    // 在新会话启动时运行的代码
            //    //if (Request.IsLocal && Request.ServerVariables["SERVER_NAME"].IsIpaddress()) return;
            //    if (Response.Cookies["ASP.NET_SessionId"] == null) return;
            //    Response.Cookies["ASP.NET_SessionId"].Value = Session.SessionID;
            //    Response.Cookies["ASP.NET_SessionId"].Domain = ".Kmer.com";
            //}
            //catch (Exception ex)
            //{
            //   // Log.Error(ex);
            //}
        }

        private void Session_End(object sender, EventArgs e)
        {
            // 在会话结束时运行的代码。 
            // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
            // InProc 时，才会引发 Session_End 事件。如果会话模式设置为 StateServer
            // 或 SQLServer，则不引发该事件。
        }

        private void Application_BeginRequest(object sender, EventArgs e)
        {
            //HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Default);
        }
    }
}